#include "behavior_tree_delay_policy.h"
#include <behaviortree_cpp_v3/decorators/delay_node.h>

namespace policy
{
BehaviorTreeDelayPolicy::BehaviorTreeDelayPolicy(const std::string &name)
    : BehaviorTreePolicy(name)
{
    policy_tree_node_ = std::make_unique<BT::DelayNode>(name + "_delay_node", 0);
}
BehaviorTreeDelayPolicy::BehaviorTreeDelayPolicy(const std::string &name, uint32_t delay_mill_second)
    : BehaviorTreePolicy(name)
{
    policy_tree_node_ = std::make_unique<BT::DelayNode>(name + "_delay_node", delay_mill_second);
}
BehaviorTreeDelayPolicy::~BehaviorTreeDelayPolicy() = default;

void policy::BehaviorTreeDelayPolicy::setDelayMilliSecond(uint32_t milli_second)
{
    auto *delay_node = dynamic_cast<BT::DelayNode *>(policy_tree_node_.get());
    if (nullptr == delay_node)
    {
        throw std::runtime_error("delay tree node case fail");
    }
    delay_node->setDelayMilliSecond(milli_second);
}
}
